package com.day1012.morning;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
获取属性
 */
public class MainText1 {
    public static void main(String[] args) throws Exception {
        Map<Integer,String> map = new HashMap<>();
        map.put(1,"public");
        map.put(2,"private");
        map.put(3,"protected");
        Class<Student> clazz = Student.class;
        //   getDeclaredFields()  获取所有的属性
        Field[] fields = clazz.getDeclaredFields();
        for (Field f : fields) {
            System.out.print(map.get(f.getModifiers()) + " ");
            System.out.print(f.getType() + " ");
            System.out.println(f.getName());
        }
        Student student = new Student();
        //  属性的取值和赋值
        Field stu_num = clazz.getDeclaredField("stu_num");
        //   私有的
        stu_num.setAccessible(true);
        stu_num.set(student,"1003");
        System.out.println("正常取值：" + student.getStu_num());
        System.out.println("反射取值：" + stu_num.get(student));

    }
}
